<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class minfo extends CI_Model {

    var $theme_data = array(
        'layout_main' => 'layout',
        'left' => 'include/leftcp',
    );
    public $mytable = "info";
    public $primaryKey = "INF_ID";
    public $resCode = "INFO";

    function __construct() {
        parent::__construct();
    }

    function field() {
	$fieldData = array();
	$fieldData['INFCATE_ID'] = 0;
	$fieldData['INF_TITLE'] = '';
	$fieldData['INF_CONTENT'] = '';
	$fieldData['INF_TIME_CREATE'] = time();
	$fieldData['INF_TIME_UPDATE'] = time();
	$fieldData['SEO_H1'] = '';
	$fieldData['SEO_KEYWORD'] = '';
	$fieldData['SEO_DESCRIPTION'] = '';
	$fieldData['SEO_METATITLE'] = '';
	$fieldData['INF_STATUS'] = 1;
	$fieldData['INF_CODE'] = '';
	$fieldData['INF_SHORT_CONTENT'] = '';
	$fieldData['INF_THUMB'] = '';
	$fieldData['INF_ORDER'] = 0;
	return $fieldData;
    }

    function get($val = '', $param = null) {
        if ($param == null)
            $param = $this->primaryKey;

        if (is_array($val) && $val != array())
            $this->db->where($val);
        else if ($val != '')
            $this->db->where($param, $val);

        $this->db->from($this->mytable);
        return $this->db->get()->first_row();
    }

    function gets($val = '', $param = null) {
        if ($param == null)
            $param = $this->primaryKey;
        if (is_array($val) && $val != array())
            $this->db->where($val);
        else if ($val != '')
            $this->db->where($param, $val);

        $this->db->from($this->mytable);
        return $this->db->get()->result();
    }

    function where_in($val = '', $param = null) {
        if ($param == null)
            $param = $this->primaryKey;

        $this->db->from($this->mytable);
        if ($val != '')
            $this->db->where_in($this->mytable . "." . $param, $val);
        return $this->db->get()->result();
    }

    function num($val = '', $param = null) {
         if ($param == null)
            $param = $this->primaryKey;
        if (is_array($val) && $val != array())
            $this->db->where($val);
        else if ($val != '')
            $this->db->where($param, $val);
		
        $this->db->from($this->mytable);
        return $this->db->count_all_results();
    }

    function update($val = '', $param = null, $arr_update) {
        if ($param == null)
            $param = $this->primaryKey;

        if ($val != '')
            $this->db->where($param, $val);
		$arr_update['OS_TIME_UPDATE'] = time();
        $arr_update = $this->msystem->update_security($arr_update, $this->field());
        $this->db->update($this->mytable, $arr_update);
    }

    function insert($arr_insert) {
        $arr_insert = $this->msystem->insert_security($arr_insert, $this->field());
        $this->db->insert($this->mytable, $arr_insert);
        return $this->db->insert_id();
    }

    function delete($val = '', $param = null) {
        if ($val != '') {
            $this->db->where($param, $val);
            $this->db->delete($this->mytable);
        }
    }
	function getImageDetail($infoID){
		$this->db->where("INF_ID",$infoID);
		$this->db->from("info_images");
		return $this->db->get()->result();
	
	}
	
	function getsInfo($val = '', $param = null) {
        if ($param == null)
            $param = $this->primaryKey;
        if (is_array($val) && $val != array())
            $this->db->where($val);
        else if ($val != '')
            $this->db->where($param, $val);

        $this->db->from($this->mytable.' as p');
		$this->db->join("infocate as s","s.INFCATE_ID = p.INFCATE_ID");
        return $this->db->get()->result();
    }
}

?>